﻿
<div ng-controller="Customer_SelfList">
    <div class="bg-light lter b-b wrapper-md">
        <h3 class="m-n font-thin h3">我的客户</h3>
    </div>
    <div class="bg-light lter b-b wrapper-md">
        <div class="row">
            <div class="col-xs-12 input-group" style="padding: 0px 15px 5px">
                <input type="text" class="form-control" id="findname" placeholder="按名称查找" ng-keyup="myKeyup($event)" ng-model="findname">
                <span class="input-group-btn">
                    <button class="btn btn-default" type="button" ng-keyup="myKeyup($event)" ng-click="find()">查找</button>
                </span>
            </div>
            <div class="btn-group col-xs-4">
                <button class="btn btn-default" ng-click="$state.go('app.Customer_AddAppr', { 'id': item.Id })">新建报备</button>
            </div>
        </div>
    </div>

    <!--<div class="container-fluid" style="padding:10px auto; border-bottom: solid red 2px" ng-repeat="item in pageData.Data">-->
    <!--<a ng-click="$state.go('app.Customer_Detail', { 'id': item.Id })">-->
    <!--<div class="row">-->
    <!--<div style="text-align: center;" class="col-xs-12"><strong>简称：</strong>{{item.ShortName}}</div>-->
    <!--</div>-->
    <!--<div class="row">-->
    <!--<div class="col-xs-6"><strong>名称：</strong>{{item.Name}}</div>-->
    <!--<div class="col-xs-6">-->
    <!--<strong>状态：</strong>-->
    <!--<span ng-if="item.ApprovalState==0">待确认</span>-->
    <!--<span ng-if="item.ApprovalState==2">已确认</span>-->
    <!--<span ng-if="item.ApprovalState==3">未通过</span>-->
    <!--</div>-->
    <!--</div>-->
    <!--<div class="row">-->
    <!--<div class="col-xs-6"><strong>联系人：</strong>{{item.ContactPosition}}</div>-->
    <!--<div class="col-xs-6">-->
    <!--<strong>电话：</strong>-->
    <!--<span>{{item.ContactPhone}}</span>-->
    <!--</div>-->
    <!--</div>-->
    <!--<div class="row">-->
    <!--<div class="col-xs-12"><strong>信誉：</strong>{{item.CreditScore}}</div>-->
    <!--</div>-->
    <!--</a>-->


    <div class="panel panel-default" style="margin-bottom: 10px" ng-repeat="item in pageData.Data">
        <a ng-click="$state.go('app.Customer_Detail', { 'id': item.Id })">
            <div class="panel-heading">
                <h3 class="panel-title">{{item.ShortName}}</h3>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-xs-6"><strong>名称：</strong>{{item.Name}}</div>
                    <div class="col-xs-6">
                        <strong>状态：</strong>
                        <span ng-if="item.ApprovalState==0">待确认</span>
                        <span ng-if="item.ApprovalState==2">已确认</span>
                        <span ng-if="item.ApprovalState==3">已驳回</span>
                    </div>
                </div>
                <div class="row" ng-repeat="x in item.CustomerContacts">
                    <div class="col-xs-6"><strong>联系人：</strong>{{x.ContactUser}}
                    </div>
                    <div class="col-xs-6">
                        <strong>电话：</strong>
                        <span>{{x.ContactPhone}}</span>
                    </div>
                </div>

                <div class="row">
                    <div class="col-xs-12"><strong>信誉：</strong>{{item.CreditScore}}</div>
                </div>
            </div>
        </a>
        <div class="panel-footer">
            <div class="row text-right">
                <!--删除客户的方法按钮-->
                <button style="margin: 5px 10px" class="btn btn-sm btn-default" ng-if="item.ApprovalState==3" ng-click="remove(item)">
                    <span class="text">删除</span>
                </button>
                <!--<button style="margin: 5px 10px" class="btn btn-sm btn-default" ng-click="addpay(item)">-->
                <!--<i class="fa fa-plus text"></i>-->
                <!--<span class="text">报款</span>-->
                <!--</button>-->
                <button style="margin: 5px 10px" class="btn btn-sm btn-default" ng-click="$state.go('app.Customer_MyAccountList', { 'id': item.Id,'from':0})">
                    <span class="text">户头管理</span>
                </button>

            </div>
        </div>
    </div>


    <!--</div>-->
    <div class="row text-center">
        <div class="panel-heading" my-pagination get-page-data="getData" mypagedata="pageData"></div>
    </div>
</div>
<script>
    angular.module('app')//非标优惠
.controller("Customer_SelfList", function ($scope, $state, $http, toSave) {
    $scope.pageData = {};
    $scope.pageData.Page = 0;
    $scope.findname = "";
    $scope.pageData.Rows = $scope.defPageRows;
    //
    $scope.getData = function (p, r) {
        if (p) {
            p = p < 1 ? 1 : p;
        } else p = 1;
        if (r) {
        } else r = $scope.defPageRows;
        toSave.save_pages_lis(p, r);//保存当前页码和条数
        console.log(toSave.get_pages(), toSave.get_lis());
        $http({
            url: "/api/ClientManager/Customer",
            method: "GET",
            params: { page: p, rows: r, name: $scope.findname }
        })
        .then(function (res) {
            $scope.pageData = res.data;
            console.log(res);
        }, function (error) {
            if (error) {
                alert("数据获取失败");
            }
        });
    };
    //                报款
    $scope.addpay = function (item) {
        $state.go('app.ClientManager_PaymentInfo', {
            id: JSON.stringify(item),
            from: "0"
        });
    };
    //                删除客户方法
    $scope.remove = function (item) {
        console.log(item);
        //                    $scope.pageData.Data.splice(item,1);
        if (confirm("确定删除")) {
            $http({
                url: "../api/Customer/Delete?customerId=" + item.Id,
                method: "DELETE"
            })
                    .then(function (res) {
                        alert("删除成功");
                        window.location.reload();
                    })
                    .then(function (error) {
                        if (error) {
                            console.log(error);
                            console.log(111111111);

                        }
                    });
        } else {
            console.log("操作取消");
        }
    }
    // $scope.getData(1,$scope.pageData.Rows);
    $scope.find = function () {
        $scope.getData(1, $scope.pageData.Rows);
        toSave.save_inputs();//点击查询先保存input里面的值
        console.log(toSave.get_inputs('findname'))
    };
    $scope.myKeyup = function (e) {
        var keycode = window.event ? e.keyCode : e.which;
        if (keycode == 13) {
            $scope.find();
        }
    }

    if (toSave.get_inputs('findname')) {
        $scope.findname = toSave.get_inputs('findname');//把保存该id名的值取出来赋值给input框
        // alert(111)
        $scope.getData(toSave.get_pages(), toSave.get_lis());
        console.log(toSave.get_pages(), toSave.get_lis());
    } else {
        $scope.getData(toSave.get_pages(), $scope.pageData.Rows);
    }
})


</script>
<script src="js/services/toSave.js"></script>
